//
//  ManagerSheetView.m
//  Manager
//
//  Created by Mr.Lee on 2018/4/18.
//  Copyright © 2018年 Reabam. All rights reserved.
//

#import "ManagerSheetView.h"

#define BTNHEIGHT 50


@implementation ManagerSheetView
{
    UIView *coverView;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)init
{
    self=[super init];
    if (self) {
        [self createUI];
//        [self setAutoLayout];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame{
//    CGRect bounds = [UIScreen mainScreen].bounds;
    CGRect frame1 = CGRectMake(0, ScreenHeight, ScreenWidth, BTNHEIGHT*3+20);
//    self = [super initWithFrame:frame];
    
    self = [super initWithFrame:frame1];
    if (self == nil) {
        [self createUI];
    }
    
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    
    coverView=[[UIView alloc]initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];
    coverView.backgroundColor=[UIColor blackColor];
    coverView.alpha=0.35;
    [self.window addSubview:coverView];
    
    UIButton *hideBtn = [[UIButton alloc] init];
    hideBtn.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    hideBtn.tag = 10001;
    [hideBtn setBackgroundColor:[UIColor clearColor]];
    [hideBtn addTarget:self action:@selector(hideBtn:) forControlEvents:UIControlEventTouchUpInside];
    [coverView addSubview:hideBtn];
    
    [self.window addSubview:self];
    self.backgroundColor = [UIColor whiteColor];
    
    return self;
}

- (void)hideBtn:(UIButton *)sender{
    [self hideView];
    if ([self.delegate respondsToSelector:@selector(optionBtnClick:)]) {
        [self.delegate optionBtnClick:sender];
    }
}


- (void)layoutSubviews{
    [super layoutSubviews];
    self.height = BTNHEIGHT*3+20;
    self.width = ScreenWidth;
}
- (void)createUI {
    
    UIView *contentView = [[UIView alloc] init];
    contentView.frame = CGRectMake(0, 10, ScreenWidth, BTNHEIGHT*3);
    contentView.backgroundColor = [UIColor whiteColor];
    [self addSubview:contentView];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.frame = CGRectMake(0, 0, ScreenWidth, 0.5);
    lineView.backgroundColor = [UIColor colorWithHexString:@"cccccc"];
    [self addSubview:lineView];
    
    UIButton *clickBtn1 = [[UIButton alloc] init];
    self.clickBtn1 = clickBtn1; 
    clickBtn1.backgroundColor = [UIColor whiteColor];
    clickBtn1.frame = CGRectMake(0, 0, ScreenWidth, BTNHEIGHT);
    [clickBtn1 setTitle:@"统计表" forState:UIControlStateNormal];
    [clickBtn1 setTitleColor:lanse forState:UIControlStateSelected];
    [clickBtn1 setTitleColor:[UIColor colorWithHexString:@"333333"] forState:UIControlStateNormal];
    clickBtn1.titleLabel.font = [UIFont systemFontOfSize:17.0];
    clickBtn1.tag = 0;
    [clickBtn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:clickBtn1];
    UIView *lineView1 = [[UIView alloc] init];
    lineView1.frame = CGRectMake(10, clickBtn1.bottom-0.5, ScreenWidth-20, 0.5);
    lineView1.backgroundColor = [UIColor colorWithHexString:@"f4f4f4"];
    [contentView addSubview:lineView1];

    UIButton *clickBtn2 = [[UIButton alloc] init];
    self.clickBtn2 = clickBtn2;
    clickBtn2.backgroundColor = [UIColor whiteColor];
    clickBtn2.frame = CGRectMake(0, lineView1.bottom, ScreenWidth, BTNHEIGHT);
    [clickBtn2 setTitle:@"统计图" forState:UIControlStateNormal];
    [clickBtn2 setTitleColor:lanse forState:UIControlStateSelected];
    [clickBtn2 setTitleColor:[UIColor colorWithHexString:@"333333"] forState:UIControlStateNormal];
    clickBtn2.titleLabel.font = [UIFont systemFontOfSize:17.0];
    clickBtn2.tag = 1;
    [clickBtn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:clickBtn2];
    UIView *lineView2 = [[UIView alloc] init];
    lineView2.frame = CGRectMake(10, clickBtn2.bottom-0.5, ScreenWidth-20, 0.5);
    lineView2.backgroundColor = [UIColor colorWithHexString:@"f4f4f4"];
    [contentView addSubview:lineView2];
    
    
    UIButton *clickBtn3 = [[UIButton alloc] init];
    clickBtn3.backgroundColor = [UIColor whiteColor];
    clickBtn3.frame = CGRectMake(0, lineView2.bottom, ScreenWidth, BTNHEIGHT);
    [clickBtn3 setTitle:@"取消" forState:UIControlStateNormal];
    [clickBtn3 setTitleColor:[UIColor colorWithHexString:@"666666"] forState:UIControlStateSelected];
    [clickBtn3 setTitleColor:[UIColor colorWithHexString:@"666666"] forState:UIControlStateNormal];
    clickBtn3.titleLabel.font = [UIFont systemFontOfSize:17.0];
    clickBtn3.tag = 2;
    [clickBtn3 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:clickBtn3];
    UIView *lineView3 = [[UIView alloc] init];
    lineView3.frame = CGRectMake(10, clickBtn3.bottom-0.5, ScreenWidth-20, 0.5);
    lineView3.backgroundColor = [UIColor colorWithHexString:@"f4f4f4"];
    [contentView addSubview:lineView3];
    

//    NSArray *Arr = @[@"统计表", @"统计图",@"取消"];
//    CGFloat x = 0;
//    CGFloat y = 0;
//    for (int i = 0; i < 3 ; i ++) {
//        y = i * BTNHEIGHT;
//        UIButton *clickBtn = [[UIButton alloc] init];
//        clickBtn.backgroundColor = [UIColor whiteColor];
//        clickBtn.frame = CGRectMake(x, y, ScreenWidth, BTNHEIGHT);
//        [clickBtn setTitle:Arr[i] forState:UIControlStateNormal];
//
//        [clickBtn setTitleColor:lanse forState:UIControlStateSelected];
////         [clickBtn setTitleColor:lanse forState:UIControlStateHighlighted];
//        [clickBtn setTitleColor:[UIColor colorWithHexString:@"333333"] forState:UIControlStateNormal];
//
//
//        if (i == 0) {
////            [clickBtn setTitleColor:lanse forState:UIControlStateNormal];
//        } else if (i == 1){
////            [clickBtn setTitleColor:[UIColor colorWithHexString:@"333333"] forState:UIControlStateNormal];
//        } else{
//            [clickBtn setTitleColor:[UIColor colorWithHexString:@"666666"] forState:UIControlStateNormal];
//        }
//
//
//        clickBtn.titleLabel.font = [UIFont systemFontOfSize:17.0];
//        clickBtn.tag = i;
//        [clickBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
//        [contentView addSubview:clickBtn];
//
//        UIView *lineView = [[UIView alloc] init];
//        lineView.frame = CGRectMake(10, clickBtn.bottom-0.5, ScreenWidth-20, 0.5);
//        lineView.backgroundColor = [UIColor colorWithHexString:@"f4f4f4"];
//        [contentView addSubview:lineView];
//
//
//    }

    
}
- (void)btnClick:(UIButton *)sender{

//    sender.selected = YES;
    
    [self hideView];
    if ([self.delegate respondsToSelector:@selector(optionBtnClick:)]) {
        [self.delegate optionBtnClick:sender];
    }
    
}
- (void)show{

    [UIView animateWithDuration:0.5 animations:^{
        self.frame = CGRectMake(0, ScreenHeight-self.frame.size.height, self.frame.size.width, self.frame.size.height);
    }];
    
}

- (void)hideView{

    [UIView animateWithDuration:0.5 animations:^{
        self.frame = CGRectMake(0, ScreenHeight, self.frame.size.width, self.frame.size.height);
    } completion:^(BOOL finished) {
            self.window = nil;
            [coverView removeFromSuperview];
    }];

  
}

- (void)hide{
    [self hideView];
}
@end
